﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CommunitySystemModel;
using CommunitySystem.BO.EmpbasicBO;
using CommunitySystem.BO;

namespace CommunitySystem.Web.Service
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“ZhaoLuService”。
    public class ZhaoLuService : IZhaoLuService
    {
        private ZhaoLuBO bo = new ZhaoLuBO();
        private EmpbasicBO ebo = new EmpbasicBO();

        public bool InsertMianShiEmp(ObservableCollection<ZL_MianShiEmpPiPeiModel> model)
        {
            return bo.InsertMianShiEmp(model);
        }
        public ObservableCollection<ZhaoLuZhiWeiModel> GetZhaoLuZhiWeiForMianShi(int year)
        {
            return bo.GetZhaoLuZhiWeiForMianShi(year);
        }
        public ObservableCollection<ZhaoLuZhiWeiModel> GetZhaoLuZhiWei(string OrgID, int ID, int start, int end, int status,
                                                                int year, string islocked)
        {
            return bo.GetZhaoLuZhiWei(OrgID, ID, start, end, status, year, islocked);
        }

        public bool DeteleZhaoLuZhiWei(string ID)
        {
            return bo.DeteleZhaoLuZhiWei(ID);
        }

        public bool SaveZhaoLuZhiWei(string ID)
        {
            return bo.SaveZhaoLuZhiWei(ID);
        }

        public string ChaKanShiFouDouShenHeZhaoLuZhiWei(string OrgID, int year, string islocked)
        {
            return bo.ChaKanShiFouDouShenHeZhaoLuZhiWei(OrgID, year, islocked);
        }

        public int GetZhaoLuZhiWeiCount(string OrgID, int ID, int status, int year, string islocked)
        {
            return bo.GetZhaoLuZhiWeiCount(OrgID,ID, status, year, islocked);
        }

        public bool CheckZhaoLuZhiWei(string ID)
        {
            return bo.CheckZhaoLuZhiWei(ID);
        }

        public bool TuiZhaoLuZhiWei(string ID, string memo)
        {
            return bo.TuiZhaoLuZhiWei(ID, memo);
        }

        public bool FaBuZhaoLuZhiWei(string ID, int zhaolujihuaid)
        {
            return bo.FaBuZhaoLuZhiWei(ID,zhaolujihuaid);
        }

        public bool CancelZhaoLuZhiWei(string ID)
        {
            return bo.CancelZhaoLuZhiWei(ID);
        }

        public bool AddZhaoLuZhiWei(ZhaoLuZhiWeiModel item)
        {
            return bo.AddZhaoLuZhiWei(item);
        }
        
        public bool UpdateZhaoLuZhiWei(ZhaoLuZhiWeiModel item)
        {
            return bo.UpdateZhaoLuZhiWei(item);
        }

        public bool SuoZhaoLuZhiWei()
        {
            return bo.SuoZhaoLuZhiWei();
        }

        public ObservableCollection<ZhaoLuJiHuaModel> GetZhaoLuJiHuaModel(int id, string islocked, int year)
        {
            return bo.GetZhaoLuJiHuaModel(id, islocked,year);
        }
        public ObservableCollection<ZhaoLuJiHuaDetailModel> GetZhaoLuJiHuaDetailModel(int id, int year)
        {
            return bo.GetZhaoLuJiHuaDetailModel(id, year);
        }
        public ObservableCollection<ZhaoLuJiHuaDetail1Model> GetZhaoLuJiHuaDetail1Model(int id, int year)
        {
            return bo.GetZhaoLuJiHuaDetail1Model(id, year);
        }

        public bool InsertZhaoLuJiHua(int ZhaoLuJiHua, ZhaoLuJiHuaDetailModel ZhaoLuJiHuaDetail,
                               ObservableCollection<ZhaoLuJiHuaDetail1Model> ZhaoLuJiHuaDetail1)
        {
            return bo.InsertZhaoLuJiHua(ZhaoLuJiHua, ZhaoLuJiHuaDetail, ZhaoLuJiHuaDetail1);
        }
        public int InsertZhaoLuJiHuaTitle(ZhaoLuJiHuaModel ZhaoLuJiHua)
        {
            return bo.InsertZhaoLuJiHuaTitle(ZhaoLuJiHua);
        }

        public bool DeleteZhaoLuJiHua(int id)
        {
            return bo.DeleteZhaoLuJiHua(id);
        }

        public FileTransferStream GetExcelFile(ZhaoLuJiHuaDetailModel model, ObservableCollection<ZhaoLuJiHuaDetail1Model> models, ObservableCollection<ZhaoLu_DaoRuKaoShengModel> zlmodels, string username, Dictionary<string, bool> dic)
        {
            return bo.GetExcelFile(model, models, zlmodels,username,dic);
        }

        public bool CanDaoRuAll(int year, int month)
        {
            return bo.CanDaoRuAll(year, month);
        }

        public bool ShanChongFu(int year, int month)
        {
            return bo.ShanChongFu(year,  month);
        }

        public bool DaoRuZhaoLuKaoSheng(ZhaoLu_DaoRuKaoShengModel model)
        {
            return bo.DaoRuZhaoLuKaoSheng(model);
        }

        public ObservableCollection<ZhaoLu_DaoRuKaoShengModel> GetZhaoLu_DaoRuKaoShengModel(int year, bool isfangqi, int month, int id, string nitongyi, string tijianhege, string zhengshenhege, DateTime? dt, string zu, string shangxiawu, string orgids)
        {
            return bo.GetZhaoLu_DaoRuKaoShengModel(year,isfangqi,month,id,nitongyi,tijianhege,zhengshenhege, dt, zu, shangxiawu,orgids);
        }

        public Dictionary<int, int> GetZL_MianShiRenShu(int PublicOfficialSelectionID, int year)
        {
            return bo.GetZL_MianShiRenShu(PublicOfficialSelectionID, year);
        }

        public ObservableCollection<ZL_ZhiWeiShiJianAnPaiModel> ZL_PublicOfficialSelectionForAnPai(int year)
        {
            return bo.ZL_PublicOfficialSelectionForAnPai(year);
        }

        public ObservableCollection<ZL_ZhiWeiShiJianAnPaiModel> ZL_PublicOfficialSelectionForAnPaiSuoDing(int year)
        {
            return bo.ZL_PublicOfficialSelectionForAnPaiSuoDing(year);
        }

        public ObservableCollection<ZhaoLuZhiWeiModel> ZL_GetPublicOfficialSelectionForDaoChu(int year, string islocked)
        {
            return bo.ZL_GetPublicOfficialSelectionForDaoChu(year, islocked);
        }

        public bool ZL_InsertZu(ZL_ZhiWeiShiJianAnPaiModel model, string type)
        {
            return bo.ZL_InsertZu(model, type);
        }

        public bool QiQuan(string ID,string huanjie)
        {
            return bo.QiQuan(ID, huanjie);
        }

        public bool UpdateZL_MianShiFenShu(ZhaoLu_DaoRuKaoShengModel model)
        {
            return bo.UpdateZL_MianShiFenShu(model);
        }

        public bool NiTongYiorNot_ZL(List<int> PublicOfficialRecordID, string istongyi)
        {
            return bo.NiTongYiorNot_ZL(PublicOfficialRecordID, istongyi);
        }
        public bool ISNiTongYi(string PublicOfficialRecordID, string istongyi)
        {
            return bo.ISNiTongYi(PublicOfficialRecordID, istongyi);
        }
        public bool UpdateZL_TiJian(ZhaoLu_DaoRuKaoShengModel model)
        {
            return bo.UpdateZL_TiJian(model);
        }
        
        public bool UpdateZL_ZhengShen(ZhaoLu_DaoRuKaoShengModel model)
        {
            return bo.UpdateZL_ZhengShen(model);
        }

        public ObservableCollection<ZhaoLuJiHuaModel> GetZhaoLuJiHuaModelForCom()
        {
            return bo.GetZhaoLuJiHuaModelForCom();
        }

        //public FileTransferStream ZhaoLu_GetExcelFile(ObservableCollection<ZhaoLu_DaoRuKaoShengModel> models, string username,
        //                                       Dictionary<string, bool> dic)
        //{
        //    return bo.ZhaoLu_GetExcelFile(models, username, dic);
        //}

        public ObservableCollection<ZhaoLu_DaoRuKaoShengModel> ZL_GetMianShiTongZhiBiao(int exameid, DateTime? dt, string zu, string shangxiawu)
        {
            return bo.ZL_GetMianShiTongZhiBiao(exameid, dt,zu,shangxiawu);
        }



        public FileTransferStream ZhaoLu_GetExcelFile1(int exameid, DateTime? dt, string zu, string shangxiawu, string username, Dictionary<string, bool> dic)
        {
            var models = bo.ZL_GetMianShiTongZhiBiao(exameid, dt, zu, shangxiawu);
            return bo.ZhaoLu_GetExcelFile(models, username, dic);
        }


        public bool UpdateZL_MianShiFenShu_LuRuWanBi(ZhaoLu_DaoRuKaoShengModel model)
        {
            return bo.UpdateZL_MianShiFenShu_LuRuWanBi(model);
        }


        public ObservableCollection<ZhaoLu_DaoRuKaoShengModel> GetZhaoLu_LuYongGuanLi(int year)
        {
            return bo.GetZhaoLu_LuYongGuanLi(year);
        }

        public bool InsertLuYongLeiXing(ObservableCollection<ZhaoLu_DaoRuKaoShengModel> models, string quedingzanhuan, DateTime? luyongriqi)
        {
            return bo.InsertLuYongLeiXing(models, quedingzanhuan,luyongriqi);
        }


        public ObservableCollection<ZhaoLuZhengShen_AttatchmentModel> GetZhaoLuZhengShen_Attatchment(int id)
        {
            return bo.GetZhaoLuZhengShen_Attatchment(id);
        }

        public bool JieSuoZhaoLuZhiWei(int id)
        {
            return bo.JieSuoZhaoLuZhiWei(id);
        }


        public bool ImportZLZW(ObservableCollection<ZhaoLuZhiWeiModel> models)
        {
            int orgidzongrenshu = 0;
            ObservableCollection<BianZhiModel> bianzhi = null;
            ObservableCollection<ZhaoLuZhiWeiModel> selZLZW = null;
            foreach (var item in models)
            {
               bianzhi= ebo.GetBianZhi_JiBenModel(string.Format("select ID from OrgForHR where Name='{0}'",item.OrgName));
                //orgidzongrenshu = models.Where(p => p.OrgName == item.OrgName).ToList().Sum(p => p.PeopleCount);
               selZLZW = bo.GetZhaoLuZhiWei(string.Format("select ID from OrgForHR where Name='{0}'", item.OrgName), 0, 0, 20, -1, item.Year, "");
               if (selZLZW != null && selZLZW.Count > 0)
               {
                   foreach (ZhaoLuZhiWeiModel i in selZLZW)
                   {
                       orgidzongrenshu = orgidzongrenshu + i.PeopleCount;
                   }
               }
                
                if(bianzhi != null && bianzhi.Count > 0)
                 {
                     if (item.PeopleCount + orgidzongrenshu +
                    (!string.IsNullOrEmpty(bianzhi[0].JiGuanXingZheng)
                         ? Convert.ToInt32(bianzhi[0].JiGuanXingZheng)
                         : 0)
                    +
                    (!string.IsNullOrEmpty(bianzhi[0].ZhengFaXingZheng)
                         ? Convert.ToInt32(bianzhi[0].ZhengFaXingZheng)
                         : 0)
                    + (!string.IsNullOrEmpty(bianzhi[0].canzhaocount) ? Convert.ToInt32(bianzhi[0].canzhaocount) : 0) >
                    (!string.IsNullOrEmpty(bianzhi[0].zongcount) ? Convert.ToInt32(bianzhi[0].zongcount) : 0))
                     {
                         item.Memo = item.Memo + "  该单位编制已满";

                     }
                     bianzhi.Clear();
                    selZLZW.Clear();
                     }
                bo.ImportZhaoLuZhiWei(item);
            }
            return true;
        }

        #region IZhaoLuService 成员


        public bool UpdateZL_MianShiFenShu_LuRuWanBiBySql(string sql)
        {
            try
            {
               if (!string.IsNullOrEmpty(sql))
                AccessHelper.GetInstance().ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                
                 Log4JClass.SetErro("面试成绩录用完毕", ex);
            }
            return true;
        }

        #endregion

  
    }
}
